<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('数据仓库列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "etl/dw";
        var tableRefresh=function() {
            let labels = $(".themeItem").find(".label");
            let dwClsArr = [];
            let cd;
            $.each(labels,function (index,item) {
                debugger;
               if($(item).hasClass("label-info")) {
                   cd = $(item).attr("cd");
                   dwClsArr.push($(item).attr("cd"));
               }
            });

            $("#sdDwcls").val(dwClsArr);
            $("#bootstrap-table").bootstrapTable('refresh');
        }
        function themeChange(type,ele) {
            debugger;
           $(ele).addClass("label-info");
           $(ele).siblings().removeClass("label-info");
           $("div.themeItem").css("display","none");
           $("div.themeItem[name='"+type+"']").css("display","");
           $("div.themeItem").find(".label").removeClass("label-info");
           $("div.themeItem[name='"+type+"']").find(".label:first").nextAll().addClass("label-info");
           tableRefresh();
        }

        function themeItemChange(type,ele) {
            debugger;
            if($(ele).hasClass("label-info")) {
                $(ele).removeClass("label-info");
                if(!($(ele).siblings().hasClass("label-info"))) {
                    $(ele).siblings(".label:first").addClass("label-info");
                }
                if(type.endsWith("_00")) { //取消全选
                    $(ele).nextAll().removeClass("label-info");
                }
            } else {
                $(ele).addClass("label-info");
                if(type.endsWith("_00")) {
                    $(ele).nextAll().addClass("label-info");
                } else {
                    $(ele).siblings(".label:first").removeClass("label-info");
                }
            }
            tableRefresh();
        }
        function fldMapping(idDrawDw,cdTb) {
            $.modal.open("表("+cdTb+")字段对照", prefix+"/fldMapping/"+idDrawDw,900,700);
        }
        function createTb(idDrawDw) {
            $.ajax({
                url: prefix+"/createTb/"+idDrawDw,
                cache: false,
                type: 'GET',
                success: function (result) {
                    if(result.code=="0") {
                        $.modal.alertSuccess("创建成功");
                    } else {
                        $.modal.alertError(result.msg);
                    }
                }
            });
        }
        function doSubmit() {
            $.modal.close();
        }
        $(function() {
            var options = {
                url: prefix + "/selectByCls",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "数据仓库",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'idDrawDw',
                    title: '',
                    visible: false
                },
                {
                    field: 'na',
                    title: '名称'
                },
                {
                    field: 'cdTb',
                    title: 'DW表'
                },
                {
                    field: 'euStatus',
                    title: '建表状态',
                    formatter: function(value, item, index) {
                        if(item.euStatus==0) {
                            return "新建";
                        } else if(item.euStatus==1) {
                            return "已创建";
                        } else if(item.euStatus==2) {
                            return "已修改";
                        }
                    }
                },
                {
                    field: 'sdSys',
                    title: '所属系统'
                },
                {
                    field: 'fldDt',
                    title: '日期字段'
                },
                {
                    field: 'cdTbTarOds',
                    title: 'ods目标表'
                },
                {
                    field: 'des',
                    title: '备注'
                },
                {
                    field: 'fgAct',
                    title: '启用标志',
                    formatter: function(value, item, index) {
                        if(item.fgAct==1) {
                            return "启用";
                        } else {
                            return "停用"
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="createTb(\'' + row.idDrawDw + '\')"><i class="fa fa-edit"></i>建表</a> ');
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="fldMapping(\'' + row.idDrawDw + '\',\''+row.cdTb+'\')"><i class="fa fa-list-ul"></i>字段</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.idDrawDw + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>